﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Bangle.Model;

namespace Bangle.BLL
{
    //T_Classification
    public partial class T_ClassificationBLL
    {

        private readonly Bangle.DAL.T_ClassificationDAL dal = new Bangle.DAL.T_ClassificationDAL();
        public T_ClassificationBLL()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ClassificationId)
        {
            return dal.Exists(ClassificationId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Bangle.Model.T_Classification model)
        {
            return dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Bangle.Model.T_Classification model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ClassificationId)
        {

            return dal.Delete(ClassificationId);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string ClassificationIdlist)
        {
            return dal.DeleteList(ClassificationIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Bangle.Model.T_Classification GetModel(int ClassificationId)
        {

            return dal.GetModel(ClassificationId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Bangle.Model.T_Classification GetModelByCache(int ClassificationId)
        {

            string CacheKey = "T_ClassificationModel-" + ClassificationId;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ClassificationId);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Bangle.Model.T_Classification)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Bangle.Model.T_Classification> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Bangle.Model.T_Classification> DataTableToList(DataTable dt)
        {
            List<Bangle.Model.T_Classification> modelList = new List<Bangle.Model.T_Classification>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Bangle.Model.T_Classification model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Bangle.Model.T_Classification();
                    if (dt.Rows[n]["ClassificationId"].ToString() != "")
                    {
                        model.ClassificationId = int.Parse(dt.Rows[n]["ClassificationId"].ToString());
                    }
                    if (dt.Rows[n]["ParentId"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["ParentId"].ToString());
                    }
                    model.ClassificationCode = dt.Rows[n]["ClassificationCode"].ToString();
                    model.ClassificationName = dt.Rows[n]["ClassificationName"].ToString();
                    model.Description = dt.Rows[n]["Description"].ToString();


                    modelList.Add(model);
                }
            }
            return modelList;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        #endregion

    }
}